﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SetSailModel;
using Dapper;

namespace SetSailDal
{
    /// <summary>
    /// 联运读档
    /// </summary>
    public static class LYCDDal
    {
        /// <summary>
        /// 新增存读档记录
        /// </summary>
        /// <param name="GGLX">公告类型</param>
        /// <returns></returns>
        public static ResultModel<int> Add_CDDJL(QH_CDDJL cddjl)
        {
            ResultModel<int> result = new ResultModel<int>();
            try
            {
                string sql = string.Format(@"INSERT INTO QH_CDDJL
                                             (
                                             	ID,
                                             	CZZH,
                                             	CDDLX,
                                             	CJSJ,
                                             	SCBJ,
                                                SYLL,
                                                CDRQ,
                                                BZ
                                             )
                                             VALUES
                                             (
                                             	@ID,
                                             	@CZZH,
                                             	@CDDLX,
                                             	GETDATE(),
                                             	0,
                                                @SYLL,
                                                @CDRQ,
                                                @BZ
                                             )");
                using (DBHelper help = new DBHelper())
                {
                    result.Count = help.DbContext.Execute(sql, cddjl);
                    if (result.Count == 0)
                    {
                        result.Code = ResultCode.Fail;
                        result.Message = "存档记录失败";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Code = ResultCode.Fail;
                result.Message = ex.Message;
            }
            return result;
        }

        /// <summary>
        /// 新增问题反馈
        /// </summary>
        /// <param name="GGLX">公告类型</param>
        /// <returns></returns>
        public static ResultModel<int> Add_GGTX(QH_GGTX ggtx)
        {
            ResultModel<int> result = new ResultModel<int>();
            try
            {
                string sql = string.Format(@"INSERT INTO QH_GGTX
                                             (
                                             	ID,
                                             	GGLX,
                                             	GGNR,
                                             	FBZH,
                                             	CJSJ,
                                             	SCBJ
                                             )
                                             VALUES
                                             (
                                             	@ID,
                                             	@GGLX,
                                             	@GGNR,
                                             	@FBZH,
                                             	GETDATE(),
                                             	0
                                             )");
                using (DBHelper help = new DBHelper())
                {
                    result.Count = help.DbContext.Execute(sql, ggtx);
                    if (result.Count == 0)
                    {
                        result.Code = ResultCode.Fail;
                        result.Message = "公告发布失败";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Code = ResultCode.Fail;
                result.Message = ex.Message;
            }
            return result;
        }
    }
}
